<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">

    <title>Invoice</title>

    <?php $this->load->view('library/header');?>
</head>

<body class="sticky-header">

<section>
    <?php $this->load->view('library/left');?>

    <!-- main content start-->
    <div class="main-content" >

        <?php $this->load->view('library/top');?>

        <!--body wrapper start-->
        <div class="wrapper">
            <div class="panel">
                <div class="panel-body invoice">
                    <div class="row">
                        <div class="col-md-4 col-sm-4">
                            <h1 class="invoice-title">invoice</h1>
                        </div>
                        <div class="col-md-4 col-md-offset-4 col-sm-4 col-sm-offset-4">
                            <h2 class="corporate-id">发货地址</h2>
                                <?php echo $order_info['country'] . ', ' . $order_info['province'] . ', ' . $order_info['city'];?><br>
                                <?php echo $order_info['address'];?> <br>
                                收货人: <?php echo $order_info['user_name'];?>,
                                邮件: <?php echo $order_info['email'];?>
                                <br>
                                邮编: <?php echo $order_info['zip'];?>,
                                电话 : <?php echo $order_info['phone'];?>
                            </p>
                        </div>
                    </div>
                    <div class="invoice-address">
                        <div class="row">
                            <div class="col-md-5 col-sm-5">
                                <div class="inv-col"><span>订单号#</span> <?php echo $order_info['order_sn'];?>, <span>站点 :</span> <?php echo $siteweb_info['web_name'];?></div>
                                <div class="inv-col"><span>下单时间 :</span> <?php echo date('Y-m-d H:i:s', $order_info['add_time']);?></div>
                                <div class="inv-col"><span>付款时间 :</span> <?php echo date('Y-m-d H:i:s', $order_info['pay_time']);?></div>
                                <div class="inv-col"><span>状态 :</span> 已审核,<?php echo "{$order_info['pay_status_name']},{$order_info['order_status_name']},{$order_info['shipping_status_name']}";?></div>
                            </div>
                            <div class="col-md-4 col-md-offset-3 col-sm-4 col-sm-offset-3">
                                <div class="inv-col"><span>支付方式 :</span> <?php echo $order_info['payment_name'];?></div>
                                <div class="inv-col"><span>运输方式 :</span> <?php echo $order_info['shipping_name'];?></div>
                                <div class="inv-col"><span>发货单号 :</span> <?php echo $order_info['shipping_no'] ? ('<i id="t-shipping-no">' . $order_info['shipping_no'] . '</i>') : '<input id="shipping-no" class="no" value="" /><button class="btn btn-info btn-xs btn-shipping-no" style="margin-top: 0; line-height: 23px;" type="button">确认</button>';?></div>
                                <div class="inv-col"><span>paypal交易号 :</span> <i><?php echo $order_info['payment_no'] ? $order_info['payment_no'] : 'N/A';?></i></div>
                            </div>
                        </div>
                    </div>
                </div>
                <table class="table table-bordered table-invoice">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th class="text-center">图片</th>
                        <th class="text-center">货号</th>
                        <th>属性</th>
                        <th class="text-center">价格</th>
                        <th class="text-center">重量</th>
                        <th class="text-center">购买数量</th>
                        <th class="text-center">入库数量</th>
                        <th class="text-center">Total</th>
                        <th class="text-center">状态</th>
                        <th width="10%" class="text-center">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($order_goods as $item):?>
                    <tr>
                        <td><?php echo $item['rec_id'];?></td>
                        <td class="text-center"><img width="60" src="<?php echo $item['original_img'];?>" /></td>
                        <td class="text-center">
                            <?php echo $item['sku_num_sn'];?><br />
                            <span style="color: #2f6499;"><?php echo $item['sku_sn'];?></span>
                            <?php foreach ($item['shelves'] as $shelves): ?>
                            <br />
                            <span style="color: #389930;"><?php echo "货架位：{$shelves['sl_title']}";?></span>
                            <?php endforeach;?>
                        </td>
                        <td><?php echo $item['goods_attr'];?></td>
                        <td class="text-center"><strong>$ <?php echo $item['goods_price'];?></strong></td>
                        <td class="text-center"><?php echo $item['goods_weight'];?></td>
                        <td class="text-center"><strong><?php echo $item['goods_number'];?></strong></td>
                        <td class="text-center"><strong><?php echo $item['occupy_inventory_num'];?></strong></td>
                        <td class="text-center"><strong>$<?php echo $item['goods_price'] * $item['goods_number'];?></strong></td>
                        <td class="text-center"><?php echo $goods_status[$item['status']];?></td>
                        <td>
                            <?php if ($item['status'] < 4) :?>
                            <?php if ($item['goods_number'] > $item['occupy_inventory_num'] && $item['sku_number'] > 0) : ?>
                                <a class="btn btn-xs btn-info a-ajax" href="<?php echo base_url('order/inv_goods_number/rec_id/' . $item['rec_id']);?>">占用库存</a>
                            <?php endif;?>
                            <?php if ($order_info['shipping_status'] == 0): ?>
                                <a class="btn btn-xs btn-danger a-ajax" href="<?php echo base_url('order/cancel_order_goods/rec_id/' . $item['rec_id']); ?>">取消</a>
                            <?php endif;?>
                            <?php endif;?>
                        </td>
                    </tr>
                    <?php endforeach;?>
                    <tr>
                        <td colspan="8" class="payment-method" style="vertical-align: top !important; text-align: left;">
                            <p>商品总金额：USD<?php echo $order_info['goods_amount'];?> - 折扣：USD<?php echo $order_info['discounts_amount'];?> + 配送费用：USD<?php echo $order_info['shipping_fee'];?></p>
                        </td>
                        <td class="text-right" style="padding: 0 20px;" colspan="3">
                            <p style="margin-top: 50px;"><strong>订单总金额: <?php echo $order_info['order_amount'];?></strong></p>
                            <p>已退款金额: 0.00</p>
                        </td>
                    </tr>

                    </tbody>
                </table>
            </div>

            <div class="panel">
                <form id="handle_log" action="<?php echo base_url('Order/handle_log/order_id/'. $order_info['order_id']);?>" class="form-horizontal adminex-form" method="post" accept-charset="utf-8">
                    <textarea name="info" class="form-control input-lg p-text-area" rows="2" placeholder="输入备注信息..."></textarea>
                    <footer class="panel-footer">
                        <iframe class="btn btn-post pull-right btn-ajax-print" id="iPrint" style="width:80px;height:40px;display: none;" src=""></iframe>
                        <a href="<?php echo base_url('ShopifyApi/cne_order/order_id/' . $order_info['order_id']); ?>" target="_blank" class="btn btn-post pull-right btn-ajax-print">打印运单</a>
                        <button type="button" onclick="nc_href();" class="btn btn-post pull-right">打印订单</button>
                        <?php if ($order_info['order_status'] == 3) :?>
                            <button type="button" name="handle_type" value="1" class="btn btn-post pull-right btn-ajax">回传Shopify</button>
                        <?php endif;?>

                        <?php if ($order_info['order_status'] < 3 && $order_info['shipping_status'] == 0) :?>
                        <button type="button" name="handle_type" value="2" style="margin-left: 10px;" class="btn btn-danger pull-right btn-ajax">取消订单</button>
                        <?php endif;?>
                        <button type="button" name="handle_type" value="0" class="btn btn-post pull-right">备注</button>
                        <ul class="nav nav-pills p-option"></ul>
                    </footer>
                </form>
            </div>

            <div class="panel">
                <header class="panel-heading">
                    操作记录
                    <span class="tools pull-right">
                                    <a class="fa fa-chevron-down" href="javascript:;"></a>
                                 </span>
                </header>
                <div class="panel-body">
                    <?php if ($order_log) :?>
                    <table class="table  table-hover general-table">
                        <thead>
                        <tr>
                            <th width="5%"> 操作员</th>
                            <th width="5%" class="hidden-phone">订单状态</th>
                            <th width="5%">配送状态</th>
                            <th width="5%">支付状态</th>
                            <th width="15%">备注信息</th>
                            <th width="10%">添加时间</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php foreach ($order_log as $row):?>
                            <tr>
                                <td><?php echo $row['admin_name'] ? $row['admin_name'] : '系统';?></td>
                                <td class="hidden-phone"><?php echo $status['order_status'][$row['order_status']];?></td>
                                <td><?php echo $status['shipping_status'][$row['shipping_status']];?></td>
                                <td><?php echo $status['pay_status'][$row['pay_status']];?></td>
                                <td><?php echo $row['log_info'];?></td>
                                <td><?php echo date('Y-m-d H:i:s', $row['add_time']);?></td>
                            </tr>
                        <?php endforeach;?>
                        </tbody>
                    </table>
                    <?php else:?>
                        <p>无消息</p>
                    <?php endif;?>
                </div>
            </div>

        </div>
        <!--body wrapper end-->

        <!--footer section start-->
        <footer class="">
            2014 &copy; AdminEx by
        </footer>
        <!--footer section end-->


    </div>
    <!-- main content end-->
</section>
<iframe id="iPrint" style='height:0; width:0; display: none;' <?php echo $order_info['print_shipping'] ? ('src="' . $order_info['print_shipping'] . '"') : '';?> ></iframe>
<?php $this->load->view('library/footer');?>
<script type="text/javascript">

    $(function () {
        <?php if ($order_info['print_shipping']):?>
        if (document.getElementById("iPrint").attachEvent) {

            document.getElementById("iPrint").attachEvent("onload", function () { document.getElementById("iPrint").focus(); document.getElementById("iPrint").contentWindow.print(); });


        } else {
            document.getElementById("iPrint").onload = function () {
                document.getElementById("iPrint").focus(); document.getElementById("iPrint").contentWindow.print();
            }
        }
        <?php endif;?>
    });
    
    function nc_href()
    {
        window.location.href = '<?php echo base_url('Order/print_info/order_id/'.$order_info['order_id']); ?>';
    }
    
    $('.btn-ajax-print').click(function () {

        var t = setTimeout(function() {
            swal({
                imageUrl: '/public/images/Forrest.gif',
                title: '稍等...',
                allowOutsideClick: false,
                showConfirmButton: false
            });
        }, 200);

        var url = $(this).attr('href');

        $.get(url, {is_ajax: 1}, function (data) {
            clearTimeout(t);
            if (data.status == 'success') {
                $("#iPrint").attr('src', data.data.url).show();
                swal({
                    title: data.info,
                    text: '2秒后关闭',
                    type: data.status,
                    allowOutsideClick: false,
                    timer: data.stop ? data.stop : 1500,
                    showConfirmButton: false
                }).then(function (value) {
                    $("#iPrint").attr('src', data.data.url).show();
                });
            } else {
                swal({
                    title: data.info,
                    text: '2秒后关闭',
                    type: data.status,
                    allowOutsideClick: false,
                    timer: data.stop ? data.stop : 1500,
                    showConfirmButton: false
                }).then(function(isConfirm) {
                    location.reload();
                });
            }
            
        }, 'json');

        return false;
    });

    $('.a-ajax').click(function () {

        var url = $(this).attr('href');

        $.get(url, {is_ajax: 1}, function (data) {
            swal({
                title: data.info,
                text: '2秒后关闭',
                type: data.status,
                allowOutsideClick: false,
                timer: data.stop ? data.stop : 1500,
                showConfirmButton: false
            }).then(function(isConfirm) {
                location.reload();
            });

        }, 'json');

        return false;
    });


    $('#t-shipping-no').dblclick(function () {
        $(this).after('<input id="shipping-no" class="no" value="" /><button class="btn btn-info btn-xs btn-shipping-no" style="margin-top: 0; line-height: 23px;" type="button">确认</button>');
    });

    $('button[name="handle_type"]').click(function () {

        var t = setTimeout(function() {
            swal({
                imageUrl: '/public/images/Forrest.gif',
                title: '稍等...',
                allowOutsideClick: false,
                showConfirmButton: false
            });
        }, 200);

        var obj = $('#handle_log').serialize();
        var url = $('#handle_log').attr('action');
        obj += "&handle_type=" + $(this).val();

        $.post(url, obj, function(data){
            clearTimeout(t);
            swal({
                title: data.info,
                text: '2秒后关闭',
                type: data.status,
                allowOutsideClick: false,
                timer: 1500,
                showConfirmButton: false
            }).then(function(isConfirm) {
                location.reload();
            });
        },'json');
        return false;
    });

    $("body").on("click", ".btn-shipping-no", function () {
        $.post("<?php echo base_url('Order/ajax_add_shipping_no'); ?>", { shipping_no: $("#shipping-no").val(), order_id: '<?php echo $order_info['order_id'];?>'}, function(data){
            swal({
                title: data.info,
                text: '2秒后关闭',
                type: data.status,
                allowOutsideClick: false,
                timer: 1500,
                showConfirmButton: false
            }).then(function(isConfirm) {
                location.reload();
            });
        },'json');
    });
    $('.no').bind('keypress', function (event) {
        if (event.keyCode == "13") {
            $(".btn-shipping-no").click();
        }
    })
</script>

<!--common scripts for all pages-->
<script src="/public/js/scripts.js"></script>

</body>
</html>
